# Weather classes for pyplant
if __debug__:
    from SimPy.SimulationTrace import *
else:
    from SimPy.Simulation import *

class Weather(Process):
    def __init__(self,name,raininterval,rainperiod,watersources):
        Process.__init__(self,name=name)
        self.raininterval = int(raininterval)*24
        self.rainperiod = int(rainperiod)*24
        self.watersources = watersources
        print "Interval %d, Period %d" % (self.raininterval, self.rainperiod)

    def rain(self):
        while 1:
            yield hold, self, self.raininterval
            print now(), self.name, "Started raining for %d hours" % self.rainperiod
            start = now()
            while now() < start + self.rainperiod:
                for water in self.watersources:
                    yield put, self, water, water.capacity-water.amount
                    print now(), self.name, "RAINING!"
                    yield hold, self, 24
